//
//  MqInfoTagTableViewCell.m
//  Meiqi
//
//  Created by 王郑 on 16/1/18.
//  Copyright © 2016年 KFC. All rights reserved.
//

#import "MqInfoTagTableViewCell.h"
#import "MqTagModel.h"
#import "MqInfoMoreViewController.h"
@implementation MqInfoTagTableViewCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    
        
        _tagView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 100*kHeightBase)];
        [self.contentView addSubview:_tagView];
        
        
        }
    return self;
}

- (void)buttonClick:(UIButton *)button
{
    
    MqTagModel *model = _tagModelArray[button.tag - 200];
    NSString *url = [NSString stringWithFormat:@"http://www.biketo.com/app.php?m=client&a=getArticleTagOrTagListByType&tagid=%@&type=tagNewsList",model.tagid];
    NSString *title = model.tagname;
    NSDictionary *dic = @{
                          @"url":url,
                          @"title":title
                          };
    [[NSNotificationCenter defaultCenter]postNotificationName:@"morePush" object:self userInfo:dic];
    
    
}


- (void)setTagModelArray:(NSMutableArray *)tagModelArray
{
    
    _tagModelArray = tagModelArray;
    for (int i = 0; i < _tagModelArray.count; i++) {
        
         MqTagModel *model = tagModelArray[i];
        UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
        button.frame = CGRectMake(10*kWidthBase * (i % 3 + 1) + (i % 3)*100*kWidthBase, 10*kHeightBase + i / 3 * 30 *kHeightBase, 100 * kWidthBase, 30*kHeightBase);
        button.tag = 200 + i;
        button.layer.cornerRadius = 8;
        button.layer.masksToBounds = YES;
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [self.contentView addSubview:button];
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:(UIControlEventTouchUpInside)];
        [button setTitle:model.tagname forState:(UIControlStateNormal)];
        [_tagView addSubview:button];

   }
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
